package recursiveDescent.entity;

import java.util.HashMap;
import java.util.Map;

import util.ParseUtils;

public class Automation {
	// 				\t    digit   .    $
	//
	private String state = "start";
	private Map<String, String[]> table;
	
	public Automation() {
		this.table = new HashMap<String, String[]>(){{
			put("start", new String[]{"start" , "int" , "liter",  "end"});
			put("int", new String[]{"int", "int", "liter", "end"});
			put("liter", new String[]{"liter", "liter", "end", "end"});
			put("end", new String[]{"end", "end", "end", "end"});
		}};
	}
	
	public String getNextState(char ch) {
		state = table.get(state)[this.getCol(ch)];
		return state;
	}
	
	public int getCol(char ch) {
		if (ParseUtils.isCurLineOfEnd(ch))
			return 0;
		else if(ParseUtils.isDigit(ch))
			return 1;
		else if(ch == '.')
			return 2;
		else {
			return 3;
		}
	}
}
